﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NeonLampTest.Common
{
    public class SurroundList
    {
        private SurroundNodeBase _curNode;
        private SurroundNodeBase _lastNode;
        public SurroundList()
        {
            Create();
        }
        public int Width { get; set; }
        public int Height { get; set; }
        public int Step { get; set; } = 10;
        public int SurroundWidth { get; set; } = 5;
        private void Create()
        {
            SurroundNodeBase first = new TopNode();
            first.SetDefaultColor(Color.Yellow);
            _curNode = first;
            Set(first);

            SurroundNodeBase node1=new RightNode();
            node1.SetDefaultColor(Color.Red);
            first.Next = node1;
            Set(node1);

            SurroundNodeBase node2 = new BottomNode();
            node2.SetDefaultColor(Color.Green);
            node1.Next = node2;
            Set(node2);

            SurroundNodeBase node3 = new LeftNode();
            node3.SetDefaultColor(Color.Blue);
            node2.Next = node3;
            node3.Next = first;
            Set(node3);
        }
        private void Set(SurroundNodeBase node)
        {
            node.SurroundWidth = SurroundWidth;
            node.Step = Step;
            node.Width = Width;
            node.Height = Height;
        }
        public void Draw(Graphics g)
        {
            _curNode.Draw(g);
            if (_lastNode != null)
            {
                _lastNode.Draw(g);
            }
        }
        public void Change()
        {
            Set(_curNode);
            _curNode.Width = Width;
            _curNode.Height = Height;
            _curNode.SurroundWidth = SurroundWidth;
            _curNode.Step = Step;
            _curNode.Change();
            if (_lastNode != null)
            {
                _lastNode.Change();
                _lastNode.ChangeStartColor();
            }
            if (_curNode.IsNext)
            {
                _lastNode = _curNode;
                _curNode = _curNode.Next;
                Set(_curNode);
                _curNode.Default();
            }
        }
        public void SizeChange(int width,int height)
        {
            this.Width = width;
            this.Height = height;
            _curNode.SizeChange(width, height);
            if (_lastNode != null)
            {
                _curNode.SizeChange(width, height);
            }
        }
    }
}
